package com.muqi.app.qlearn.login;

import static nl.qbusict.cupboard.CupboardFactory.cupboard;

import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.easemob.EMCallBack;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMGroupManager;
import com.muqi.app.im.qmain.EMApplication;
import com.muqi.app.im.qmain.EMHelper;
import com.muqi.app.network.http.MyAsyncHttp.AsyncCallBackListener;
import com.muqi.app.network.http.MyAsyncHttp.RESULTCODE;
import com.muqi.app.network.http.MyAsyncHttp;
import com.muqi.app.network.http.NetWorkUtils;
import com.muqi.app.network.http.ParamsUtils;
import com.muqi.app.project.application.ExitApplication;
import com.muqi.app.project.contants.MContants;
import com.muqi.app.project.contants.NetWorkApi;
import com.muqi.app.project.utils.CustomerUtil;
import com.muqi.app.project.utils.ShowToast;
import com.muqi.app.project.utils.ToastUtil;
import com.muqi.app.qlearn.fragments.TabMine;
import com.muqi.app.qlearn.modles.ChildInfo;
import com.muqi.app.qlearn.modles.UserInfo;
import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.MenuActivity;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.qlearn.student.ui.AddChildActivity;
import com.muqi.app.sharepreference.SharePreferenceUtil;
import com.muqi.app.user.db.ChildBean;
import com.muqi.app.user.db.CupboardSQLiteOpenHelper;

public class TVLoginActivity extends BaseFragmentActivity implements
		OnClickListener {

	private String id_card;
	private TextView tv_close;
	private TextView tv_login;
	private TextView tv_cancel;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.aty_tv_login);
		id_card = getIntent().getStringExtra("id_card");

	}

	@Override
	protected void onInit() {
		tv_cancel = (TextView) findViewById(R.id.tv_cancel);
		tv_close = (TextView) findViewById(R.id.tv_close);
		tv_login = (TextView) findViewById(R.id.tv_login);
		tv_cancel .setOnClickListener(this);
		tv_close .setOnClickListener(this);
		tv_login.setOnClickListener(this);

	}

	@Override
	protected void onData() {
		/** 检查是否保存了密码 ,有则取数据 */

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_login:

			tvLogin();
		case R.id.tv_cancel:

		case R.id.tv_close:

			finish();
		default:
			break;
		}
	}

	/**
	 * 登录接口
	 */
	private void tvLogin() {
		if (NetWorkUtils.isNetworkAvailable(this)) {

			HashMap<String, Object> sendMap = new HashMap<String, Object>();
			sendMap.put("token", mSpUtil.getToken());
			sendMap.put("id_card", id_card);
			String requestUrl = ParamsUtils.buildParams(
					NetWorkApi.TV_LOGIN_API, sendMap);
			MyAsyncHttp.get(this, requestUrl, new AsyncCallBackListener() {

				@Override
				public void onAsyncCallBack(RESULTCODE resuleCode,
						String request, String result) {
					if (resuleCode == RESULTCODE.SUCCESS) {
						ToastUtil.showToast(mContext, "授权成功");
						finish();
					} else {
						ToastUtil.showToast(mContext, result);
					}
				}
			});
		} else {
			ShowToast.showShort(this, R.string.net_break);// 提示无网络
		}
	}

}
